﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.ContentRendering.Api.DataEngine;

namespace ContentRenderingApi.Tool
{
    /// <summary/>
    public class ReflectionTool
    {
        private ReflectionCache _reflectionCache;

        /// <summary/>
        public ReflectionTool()
        {
            this._reflectionCache = new ReflectionCache();
        }

        /// <summary/>
        public T FetchRawProperty<T>(
            object value,
            string name)
        {
            object propertyValue = PropertyReflection.Translate(this._reflectionCache, value, name);

            // return the default
            if (propertyValue == null)
            {
                return default(T);
            }

            return (T)propertyValue;
        }

        /// <summary/>
        public object FetchRawProperty(
            object value,
            string name)
        {
            return PropertyReflection.Translate(this._reflectionCache, value, name);
        }
    }
}
